import json

import requests
from util import WeChatTokenManager

menu = {
    "button": [
        {
            "type": "click",
            "name": "统计",
            "key": "statistics"
        },
        {
            "name": "收租管理",
            "sub_button": [
                {
                    "type": "view",
                    "name": "最近三天",
                    "url": "http://www.soso.com/"
                }
            ]
        },
        {
            "type": "click",
            "name": "重置",
            "key": "V1001_GOOD"
        }
    ]
}

# 自定义菜单
def create_menu(access_token, menu):
    url = f'https://api.weixin.qq.com/cgi-bin/menu/create?access_token={access_token}'
    response = requests.post(url, data=json.dumps(menu, ensure_ascii=False).encode('utf-8'))
    return response.json()

if __name__ == '__main__':
    token_manager = WeChatTokenManager()
    token = token_manager.get_token()
    print(token)
    print(create_menu(token, menu))


